<template>
  <scroll
  class="msg-list"
  ref="scrollRef"
  >
    <div>
      <ul ref="msgsRef">
        <li v-for="(item, index) in data" v-bind:key="index" class="bubble" :class="bubbleBelone(item.userId)">
          <avatar class="msg-avatar" :src="''"></avatar>
          <div class="msg-content">{{item.content}}</div>
        </li>
      </ul>
    </div>
  </scroll>
</template>
<script>
import Scroll from '@/components/wrapScroll'
import useMessage from './use-message'
export default {
  name: 'MessageList',
  components: {
    Scroll
  },
  props: {
    data: Array
  },
  setup(props) {
    const { scrollRef, msgsRef, list, bubbleBelone } = useMessage(props)
    return {
      list,
      scrollRef,
      msgsRef,
      bubbleBelone
    }
  }
}
</script>
<style lang="scss" scoped>
.msg {
  &-list {
    position: relative;
    overflow: hidden;
    height: calc(100% - 200px);
    background-color: #fff;
    padding: 12px;
  }
}
ul {
  position: relative;
  display: flex;
  justify-content: flex-end;
  flex-direction: column;
  .msg-content {
    line-height: 21px;
    font-size: 15px;
    padding: 8px 10px;
    border-radius: 5px;
    vertical-align: top;
    position: relative;
  }
  .msg-content:before {
    position: absolute;
    top: 19px;
    display: block;
    width: 8px;
    height: 6px;
    content: '\00a0';
    -webkit-transform: rotate(29deg) skew(-35deg);
            transform: rotate(29deg) skew(-35deg);
  }
  .msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background-color: #f5f5f5;
  }
  .bubble {
    box-sizing: border-box;
    max-width: 80%;
    transition-timing-function: cubic-bezier(0.4, -0.04, 1, 1);
    display: inline-block;
    clear: both;
    margin-bottom: 8px;
  }
  .bubble:nth-of-type(1) {
    -webkit-animation-duration: 0.15s;
            animation-duration: 0.15s;
  }
  .bubble:nth-of-type(2) {
    -webkit-animation-duration: 0.3s;
            animation-duration: 0.3s;
  }
  .bubble:nth-of-type(3) {
    -webkit-animation-duration: 0.45s;
            animation-duration: 0.45s;
  }
  .bubble:nth-of-type(4) {
    -webkit-animation-duration: 0.6s;
            animation-duration: 0.6s;
  }
  .bubble:nth-of-type(5) {
    -webkit-animation-duration: 0.75s;
            animation-duration: 0.75s;
  }
  .bubble:nth-of-type(6) {
    -webkit-animation-duration: 0.9s;
            animation-duration: 0.9s;
  }
  .bubble:nth-of-type(7) {
    -webkit-animation-duration: 1.05s;
            animation-duration: 1.05s;
  }
  .bubble:nth-of-type(8) {
    -webkit-animation-duration: 1.2s;
            animation-duration: 1.2s;
  }
  .bubble:nth-of-type(9) {
    -webkit-animation-duration: 1.35s;
            animation-duration: 1.35s;
  }
  .bubble:nth-of-type(10) {
    -webkit-animation-duration: 1.5s;
            animation-duration: 1.5s;
  }
  .bubble.you {
    float: left;
    align-self: flex-start;
    -webkit-animation-name: slideFromLeft;
            animation-name: slideFromLeft;
  }
  .bubble.you .msg-avatar{
    float: left;
  }
  .bubble.you .msg-content {
    color: var(--white);
    background-color: var(--blue);
    margin-left: 48px;
  }
  .bubble.you .msg-content:before {
    left: -3px;
    background-color: var(--blue);
  }
  .bubble.me {
    float: right;
    align-self: flex-end;
    -webkit-animation-name: slideFromRight;
            animation-name: slideFromRight;
  }
  .bubble.me .msg-avatar {
    float: right;
  }
  .bubble.me .msg-content {
    color: var(--dark);
    background-color: #eceff1;
    margin-right: 48px;
  }
  .bubble.me .msg-content:before {
    right: -3px;
    background-color: #eceff1;
  }
  // 提醒
  .conversation-start {
    position: relative;
    width: 100%;
    margin-bottom: 27px;
    text-align: center;
  }
  .conversation-start span {
    font-size: 14px;
    display: inline-block;
    color: var(--grey);
  }
  .conversation-start span:before, .conversation-start span:after {
    position: absolute;
    top: 10px;
    display: inline-block;
    width: 30%;
    height: 1px;
    content: '';
    background-color: var(--light);
  }
  .conversation-start span:before {
    left: 0;
  }
  .conversation-start span:after {
    right: 0;
  }
}

@keyframes slideFromLeft {
  0% {
    margin-left: -200px;
    opacity: 0;
  }
  100% {
    margin-left: 0;
    opacity: 1;
  }
}
@-webkit-keyframes slideFromLeft {
  0% {
    margin-left: -200px;
    opacity: 0;
  }
  100% {
    margin-left: 0;
    opacity: 1;
  }
}
@keyframes slideFromRight {
  0% {
    margin-right: -200px;
    opacity: 0;
  }
  100% {
    margin-right: 0;
    opacity: 1;
  }
}
@-webkit-keyframes slideFromRight {
  0% {
    margin-right: -200px;
    opacity: 0;
  }
  100% {
    margin-right: 0;
    opacity: 1;
  }
}
</style>
